{% extends "../master.html" %}
{% block hfm_css %}
    <style>
        .layui-show-xs-block{
            float: right;
            width: 25%;
            top: 3px;
        }
        .search{
            float: right;
            position: inherit;
            bottom: 39px;
            padding: 0 12px;
        }
    </style>
{% end %}
{% block page_content %}
<div class="x-nav">
    <span class="layui-breadcrumb">
        <a href="">策略管理</a>
        <a><cite>自定义策略</cite></a>
    </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>
<div class="layui-fluid" id="component-tabs">
    <div class="layui-row">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-tab layui-tab-brief" lay-filter="component-tabs-brief">
                    <ul class="layui-tab-title">
                        <li class="layui-this">关键词策略</li>
                        <li>文本策略</li>
                        <li>图片策略</li>
                        <li>音频策略</li>
                        <li>视频策略</li>
                    </ul>
                    <!--*** 关键词 ***-->
                    <div class="layui-tab-content">
                        <div class="layui-tab-item layui-show">
                            <div class="layui-card-header KeywordTable">
                                <button class="layui-btn" onclick="xadmin.open('新建关键词策略','/keyword_strategy_add',600,500)">
                                    <i class="layui-icon layui-icon-add-1"></i>添加策略
                                </button>
                                <div class="layui-input-inline layui-show-xs-block">
                                    <input type="text" id="id_keyword" name="keyword" placeholder="请输入策略名称进行搜索" autocomplete="off" class="layui-input">
                                    <span class="layui-icon layui-icon-search search"></span>
                                </div>
                                <button type="button" class="layui-btn layui-btn-danger" id="strategy_delete" data-type="deletechoice">
                                    <i class="layui-icon layui-icon-delete"></i>删除策略
                                </button>
                            </div>
                            <!--keyword table-->
                            <div class="layui-card-body">
                                <table class="layui-table layui-form" id="keyword_table" lay-filter="keyword" style="width: 100%"></table>
                            </div>
                            <!--end keyword table-->
                        </div>
                        <!--*** 文本 ***-->
                        <div class="layui-tab-item">
                            <div class="layui-card">
                                <div class="layui-card-header TextTable">
                                    <button class="layui-btn" onclick="xadmin.open('新建文本策略','/text_strategy_add',600,500)">
                                        <i class="layui-icon layui-icon-add-1"></i>添加策略
                                    </button>
                                    <div class="layui-input-inline layui-show-xs-block">
                                        <input type="text" id="id_text" name="text" placeholder="请输入策略名称进行搜索" autocomplete="off" class="layui-input">
                                        <span class="layui-icon layui-icon-search search"></span>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-card-body">
                                <table class="layui-table layui-form" id="text_table"></table>
                            </div>
                        </div>
                        <!--*** 图片 ***-->
                        <div class="layui-tab-item">
                            <div class="layui-card">
                                <div class="layui-card-header ImageTable">
                                    <button class="layui-btn" onclick="xadmin.open('新建图片策略','/image_strategy_add',850,500)">
                                        <i class="layui-icon layui-icon-add-1"></i>添加策略
                                    </button>
                                    <div class="layui-input-inline layui-show-xs-block">
                                        <input type="text" id="id_image" name="image" placeholder="请输入策略名称进行搜索" autocomplete="off" class="layui-input">
                                        <span class="layui-icon layui-icon-search search"></span>
                                    </div>
                                </div>
                            </div>
                            <!-- image table-->
                            <div class="layui-card-body">
                                <table class="layui-table layui-form" id="image_table"></table>
                            </div>
                            <!-- image table-->
                        </div>
                        <!--*** 音频 ***-->
                        <div class="layui-tab-item">
                            <div class="layui-card-header AudioTable">
                                <button class="layui-btn" onclick="xadmin.open('新建音频策略','audio_strategy_add',600,500)">
                                    <i class="layui-icon layui-icon-add-1"></i>添加策略
                                </button>
                                <div class="layui-input-inline layui-show-xs-block">
                                    <input type="text" id="id_audio" name="audio" placeholder="请输入策略名称进行搜索" autocomplete="off" class="layui-input">
                                    <span class="layui-icon layui-icon-search search"></span>
                                </div>
                            </div>
                            <!--video table-->
                            <div class="layui-card-body">
                                <table class="layui-table layui-form" id="audio_table"></table>
                            </div>
                            <!--end video table-->
                        </div>
                        <!--*** 视频 ***-->
                        <div class="layui-tab-item">
                            <div class="layui-card-header VideoTable">
                                <button class="layui-btn" onclick="xadmin.open('新建视频策略','',600,500)">
                                    <i class="layui-icon layui-icon-add-1"></i>添加策略
                                </button>
                                <div class="layui-input-inline layui-show-xs-block">
                                    <input type="text" id="id_video" name="video" placeholder="请输入策略名称进行搜索" autocomplete="off" class="layui-input">
                                    <span class="layui-icon layui-icon-search search"></span>
                                </div>
                            </div>
                            <!--video table-->
                            <div class="layui-card-body">
                                <table class="layui-table layui-form" id="video_table"></table>
                            </div>
                            <!--end video table-->
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
//var xsrf = $('input[name="_xsrf"]').val();
layui.use('table', function() {
    var table = layui.table;
    //方法级渲染
    table.render({
        elem: '#keyword_table'
        , url: "/keyword_strategy_list"
        , method: 'post'
        //,where: {'xsrf_token':xsrf}
        , cols: [[
            {checkbox: true, fixed: true,width:80}
            , {field: 'onlykey', title: '策略编号',style:"color:#297890", align:'center',event:'Keyword'}
            , {field: 'title', title: '策略名称'}
            , {field: 'desc', title: '策略描述'}
            ,{field:'num', title: '策略内关键词数量', sort: true,style:"color:#00c3ff",align:'center'}
            , {field: 'creat_at', align:'center', title: '创建时间', sort: true}
            //,{ title: '高级选项', align:'center', toolbar: '#barDemo'}
        ]]
        , id: 'testReload'
        , page: true
        , limit: 15
        , text: {none: '目前暂无数据'}
    });
    // 高级选项
    table.on('tool(keyword)', function (obj) {
        var data = obj.data.onlykey;
        // alert(data);
        url = "/keyword/list/S_id";
        url = url.replace(/S_id/,data);
        xadmin.open('关键词列表',url);
    });
    // ***功能操作***
    var $ = layui.$, active = {
        // 策略删除
        deletechoice: function(){ //获取选中数据
            var checkStatus = table.checkStatus('testReload')
            ,data = checkStatus.data
            ,list=new Array();
            for(var i=0;i<data.length;i++){
                list[i] = data[i].title
            }
            layer.confirm('该操作为敏感操作<br>点击确认将删除选中的策略，该操作删除后无法恢复！',function(index){
                $.ajax({
                    type: "delete",
                    url: '/keyword_strategy_list',
                    async: true,
                    data:{
                        strategy_list: JSON.stringify(list),
                        action:'start',
                    },
                    success:function (data) {
                        layer.msg(data.msg);
                        setTimeout((function () {
                            location.replace(location.href)
                        }));
                    }
                });
            })
        }
        ,reload: function() {
            //执行重载
            table.reload('testReload', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                , where: {
                    id_keyword: $('#id_keyword').val()
                }
            });
            }
        };
        $('.KeywordTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

})
</script>


{% end %}